<?php

namespace App\Admin\Controllers;

use App\Models\OrderShirt;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class OrderShirtController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('衬衫订单列表')
            ->description('衬衫订单列表')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('Detail')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('Edit')
            ->description('description')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('Create')
            ->description('description')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new OrderShirt);

        $grid->id('Id')->sortable();
        $grid->order_number('订单号');
        $grid->amount('价格');
//        $grid->order_amount('Order amount');
//        $grid->shipping('Shipping');
        $grid->status('订单状态')->display(function ($status) {
            $s = '<span style="color: #ff9900;">未支付</span>';
            switch ($status) {
                case '0':
                    break;
                case '1':
                    $s = '<span style="color: #19be6b;">已支付</span>';
                    break;
            }
            return $s;
        });
//        $grid->payment_status('支付状态');
        $grid->payment_at('支付时间')->display(function ($payment_at) {
            if (!$payment_at) {
                return '';
            }
            return $payment_at;
        });
//        $grid->order_from('Order from');
//        $grid->openid('Openid');
//        $grid->unionid('Unionid');
//        $grid->wechat_nickname('Wechat nickname');
        $grid->shirt_mianliao('面料');
        $grid->shirt_lingxing('领型');
        $grid->shirt_xiuxing('袖型');
        $grid->shirt_xiuzi('绣字位置');
        $grid->shirt_xiuzicolor('刺绣颜色');
        $grid->shirt_xiuzicontent('绣字内容');
        $grid->height('身高(CM)');
        $grid->weight('体重(KG)');
        $grid->shirt_xiongxing('胸型');
        $grid->shirt_jianxing('肩型');
        $grid->shirt_fuxing('腹型');
        $grid->shirt_beibu('背部');
        $grid->recipient_phone('收件人电话');
        $grid->recipient_name('收件人姓名');
        $grid->recipient_area('收件人地区');
        $grid->recipient_address('收件人地址');
        $grid->buyer_phone('购买人电话');
        $grid->remarks('备注');
        $grid->created_at('创建时间');
//        $grid->updated_at('Updated at');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(OrderShirt::findOrFail($id));

        $show->id('Id');
        $show->order_number('Order number');
        $show->amount('Amount');
        $show->order_amount('Order amount');
        $show->shipping('Shipping');
        $show->status('Status');
        $show->payment_status('Payment status');
        $show->prepay_id('Prepay id');
        $show->payment_at('Payment at');
        $show->order_from('Order from');
        $show->openid('Openid');
        $show->unionid('Unionid');
        $show->wechat_nickname('Wechat nickname');
        $show->shirt_mianliao('Shirt mianliao');
        $show->shirt_lingxing('Shirt lingxing');
        $show->shirt_xiuxing('Shirt xiuxing');
        $show->shirt_xiuzi('Shirt xiuzi');
        $show->shirt_xiuzicolor('Shirt xiuzicolor');
        $show->shirt_xiuzicontent('Shirt xiuzicontent');
        $show->height('Height');
        $show->weight('Weight');
        $show->shirt_xiongxing('Shirt xiongxing');
        $show->shirt_jianxing('Shirt jianxing');
        $show->shirt_fuxing('Shirt fuxing');
        $show->shirt_beibu('Shirt beibu');
        $show->recipient_phone('Recipient phone');
        $show->recipient_name('Recipient name');
        $show->recipient_area('Recipient area');
        $show->recipient_address('Recipient address');
        $show->buyer_phone('Buyer phone');
        $show->remarks('Remarks');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new OrderShirt);

        $form->text('order_number', 'Order number');
        $form->decimal('amount', 'Amount')->default(0.00);
        $form->decimal('order_amount', 'Order amount')->default(0.00);
        $form->decimal('shipping', 'Shipping')->default(0.00);
        $form->switch('status', 'Status');
        $form->switch('payment_status', 'Payment status');
        $form->number('payment_at', 'Payment at');
        $form->text('order_from', 'Order from');
        $form->text('openid', 'Openid');
        $form->text('unionid', 'Unionid');
        $form->text('wechat_nickname', 'Wechat nickname');
        $form->text('shirt_mianliao', 'Shirt mianliao');
        $form->text('shirt_lingxing', 'Shirt lingxing');
        $form->text('shirt_xiuxing', 'Shirt xiuxing');
        $form->text('shirt_xiuzi', 'Shirt xiuzi');
        $form->text('shirt_xiuzicolor', 'Shirt xiuzicolor');
        $form->text('shirt_xiuzicontent', 'Shirt xiuzicontent');
        $form->number('height', 'Height');
        $form->number('weight', 'Weight');
        $form->text('shirt_xiongxing', 'Shirt xiongxing');
        $form->text('shirt_jianxing', 'Shirt jianxing');
        $form->text('shirt_fuxing', 'Shirt fuxing');
        $form->text('shirt_beibu', 'Shirt beibu');
        $form->text('recipient_phone', 'Recipient phone');
        $form->text('recipient_name', 'Recipient name');
        $form->text('recipient_area', 'Recipient area');
        $form->text('recipient_address', 'Recipient address');
        $form->text('buyer_phone', 'Buyer phone');
        $form->textarea('remarks', 'Remarks');

        return $form;
    }
}
